package com.pcxm.redis.test;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.pcxm.cm.util.FastJson;


public class RClasQueryAction{
    
    RedisService rs = RedisTool.getRedisService();
    List<Clas> claslist = new ArrayList<Clas>();
    Clas c;
    
    public String execute(){
        if (rs != null){
            System.out.println("具体实现类RedisService : " + rs);
            getAllClas();
        }
        System.out.println(FastJson.listToJson(claslist));
        return "SUCCESS";
    }
    
    private void getAllClas(){
        claslist = new ArrayList<Clas>();        
        int num = Integer.parseInt(rs.get("clas:count"));
        for (int i=0; i<num; i++){
            String cid = "clas:" + (i+1);
            c = new Clas();
            int id = Integer.parseInt(String.valueOf(rs.getHash(cid, "ID")));
            c.setId(id);
            System.out.println("ID:" + id);
            String name = (String) rs.getHash(cid, "NAME");
            c.setName(name);
            System.out.println("NAME:" + name);
            String comment = (String) rs.getHash(cid, "COMMENT");
            c.setComment(comment);
            System.out.println("COMMENT:" + comment);
            claslist.add(c);
        }
    }
    public static void main(String[] args) {
    	RClasQueryAction action = new RClasQueryAction();
    	action.execute();
	}

}